package com.qf.sk.util;

import org.apache.curator.RetryPolicy;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.retry.BoundedExponentialBackoffRetry;
import org.apache.curator.retry.ExponentialBackoffRetry;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class ZKConnUtil {


    @Bean
    public static CuratorFramework getClient(){
        System.setProperty("zookeeper.sasl.client", "false");
        //1. 创建重试策略
        RetryPolicy retryPolicy = new BoundedExponentialBackoffRetry(1000,2000,3);
        //2. 创建CuratorFramework
        CuratorFramework cf = CuratorFrameworkFactory.builder()
                .connectString("192.168.41.41:2181")
                .retryPolicy(retryPolicy)
                .build();
        //3. 开启连接
        cf.start();
        //4. 返回
        return cf;

    }

}
